public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    public int calculateMinimumHP(int[][] dungeon) {
        //1.定义dp表
        //2.初始化
        //3.填表
        //4.返回值
        int m = dungeon.length;
        int n = dungeon[0].length;
        int[][] dp = new int[m + 1][n + 1];
        for(int i = 0; i <= m; i++) dp[i][n] = Integer.MAX_VALUE;
        for(int i = 0; i <= n; i++) dp[m][i] = Integer.MAX_VALUE;
        dp[m][n - 1] = dp[m - 1][n] = 1;//假设走出房间的健康点数至少为1

        for(int i = m - 1; i >= 0; i--)
            for(int j = n - 1; j >= 0; j--)
                dp[i][j] = Math.max(Math.min(dp[i + 1][j], dp[i][j + 1]) - dungeon[i][j], 1);

        return dp[0][0];
    }
}